package com.zld.smarket.controller;

import com.zld.smarket.dao.GoodsTypeMapper;
import com.zld.smarket.pojo.Goods;
import com.zld.smarket.pojo.GoodsType;
import com.zld.smarket.result.ExceptionMsg;
import com.zld.smarket.result.ResponseData;
import com.zld.smarket.service.GoodsTypeServive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/goodsType")
public class GoodsTypeController {
    @Autowired
    private GoodsTypeServive goodsTypeServive;


    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ResponseData findList(Integer page, Integer limit) {
        return goodsTypeServive.findList(page, limit);
    }

    @RequestMapping("/getType")
    public List<GoodsType> getType() {
        return goodsTypeServive.selectAll();
    }

    @RequestMapping(value = "/add")
    public ResponseData add(GoodsType goodsType) {
        Long i = goodsType.getTypeNo();
        if (goodsTypeServive.selectbyno(i) > 0) {
            return new ResponseData(ExceptionMsg.ADDERROR);
        } else {


            goodsType.setTypeCreatetime(new Date());
            Integer integer = goodsTypeServive.addType(goodsType);
            return new ResponseData(ExceptionMsg.SUCCESS);
        }
    }

    @RequestMapping(value = "/search",method = RequestMethod.GET)
    public ResponseData search(String s,Integer page, Integer limit){
        return  goodsTypeServive.search(s,page, limit);
    }
    @RequestMapping(value = "/del")
    public ResponseData delete(Long[] ids){
        Integer integer = goodsTypeServive.deleteById(ids);
        return new ResponseData(ExceptionMsg.SUCCESS);
    }
}
